<?php 
if(isset($fromAjax) && $fromAjax == "ajax")
{
	$this->load->view('partial/searchlist');
}else {
	?>
<html>
	<head>
		<title>Welcome to GASCIAN</title>
		<?php 
			$this->load->view('partial/headlinks');
		?>
	</head>
	<body>
		<div id="doc-container" class="width-normal margin-auto">
			<div id="inner-doc-container" class="">
				<?php 
					$this->load->view('partial/header');
				?>
				<?php 
					$this->load->view('partial/navmenu');
				?>
				<div class="hr margin"></div>
				<div class="table-block">
					<div class="accordian table-block-cell width-235">
						<ul class="outerUl">
						<?php //print_r($subjects);
						if(isset($mainSubjects)){
							foreach ($mainSubjects as $msList){
								?>
								<li class="header <?php echo ($curr_mainSubject == $msList['id'])?"active":"";?>"><a><?php echo $msList['name']?></a>
								<ul class="innerUl">
								<?php 
								if(isset($subjects))
								for($i = 0; $i < count($subjects); $i++){
									if($msList['id'] == $subjects[$i]['main_subjects_ref']){
										?>
										<li><a class="ajax-link link" href="<?php echo base_url()."browse/subject/?subjectName=".$subjects[$i]['name']?>&fromAjax=ajax"><?php echo $subjects[$i]['name'];?></a></li>
										<?php
									}
								}
								?>
								</ul>
								</li>
								<?php
							}
						}
						?>
						</ul>
					</div><!-- accordian -->
					<div class="search-result table-block-cell">
					<div class="result-container border" id="search-result-ajax-container">
					<?php 
						$this->load->view('partial/searchlist');
					?>
					</div><!-- result-container -->
					</div><!-- search-result -->
				</div><!-- table-block -->
			</div><!-- inner-doc-container -->
		</div><!-- doc-container -->
		<?php 
			$this->load->view('partial/footer.php');
		?>	
	</body>
	

<script>
$(function() {
	
	$(".outerUl li a").click(function() {
		var ul = $(this).next(),
				clone = ul.clone().css({"height":"auto"}).appendTo(".accordian"),
				height = ul.css("height") === "0px" ? ul[0].scrollHeight + "px" : "0px";
		
		clone.remove();
		ul.animate({"height":height});

		if($(this).hasClass("link"))	{
			//For inner ul li a click
		
			//Call to particular ajax request
			ele = $(this).parents("ul.outerUl").find(".active");
			$(ele).removeClass("active");
			$(this).addClass("active");

		}
		return false;
	});

	$(".ajax-link").each(function(){
		$(this).click(function(e){
			makeSearchRequest($(this).attr("href"));
			e.stopPropagation();
		});
	});

});


//Make Ajax request
function makeSearchRequest(subjectNameUrl){
	$.ajax({
		url:subjectNameUrl,
		type:"get",
		success:function(result){
			$("#search-result-ajax-container").html(result);
		}
	});
}
</script>
</html>
<?php
}
?>